package org.arkeologgr.appening.eao;

import java.util.List;

import javax.enterprise.context.RequestScoped;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.arkeologgr.appening.entity.Item;

@RequestScoped
public class ItemEAO {
	
	@PersistenceContext
	private EntityManager em;
	
	public Item getItem(String entityUri) {
		return em.find(Item.class, entityUri);
	}
	
	public List<Item> findInArea(double lon1, double lat1, double lon2, double lat2) {
		TypedQuery<Item> tq = em.createQuery("select i from Item i where i.longitude between :lon1 and :lon2 and i.latitude between :lat1 and :lat2",Item.class);
		tq.setParameter("lon1", lon1);
		tq.setParameter("lon2", lon2);
		tq.setParameter("lat1", lat1);
		tq.setParameter("lat2", lat2);
		return tq.getResultList();
	}

}
